import { defineStore } from 'pinia'

//登录的用户信息
export const useUserInfoStore = defineStore('main', {
  state: () => ({
    userInfo: null,//用户信息
  }),
  actions: {
    setUser(userData) {
      this.userInfo = userData;
    },
    clearUser() {
      this.userInfo = null;
      setTimeout(()=>{
        sessionStorage.removeItem("main");
      },1000)
    },
  },
  persist: {
    enabled: true,
    strategies:[
      { storage: sessionStorage, paths: ['userInfo'] },
    ]
  }
})

//所有的工作号
export const useJobIDStore = defineStore('JobIDMain', {
  state: () => ({
    JobIDInfo: null,//用户信息
  }),
  actions: {
    setJobIDUser(userData) {
      this.JobIDInfo = userData;
    },
    clearJobIDUser() {
      this.JobIDInfo = null;
      setTimeout(()=>{
        sessionStorage.removeItem("JobIDMain");
      },1000)
    },
  },
  persist: {
    enabled: true,
    strategies:[
      { storage: sessionStorage, paths: ['JobIDInfo'] },
    ]
  }
})

//选择的聊天微信号
export const useChatInfoStore = defineStore('chatMain', {
  state: () => ({
    chatInfo: null,//选择的聊天人员
  }),
  actions: {
    setChatUser(data) {
      this.chatInfo = data;
    },
    clearChatUser() {
      this.chatInfo = null;
      setTimeout(()=>{
        sessionStorage.removeItem("chatMain");
      },1000)
    },
  },
  persist: {
    enabled: true,
    strategies:[
      { storage: sessionStorage, paths: ['chatInfo'] },
    ]
  }
})

//选择的对话人员信息
export const useChatUserStore = defineStore('sessionMain', {
  state: () => ({
    sessionInfo: null,//选择的聊天人员
  }),
  actions: {
    setSessionUser(data) {
      this.sessionInfo = data;
    },
    clearSessionUser() {
      this.sessionInfo = null;
      setTimeout(()=>{
        sessionStorage.removeItem("sessionMain");
      },2000)
    },
  },
  persist: {
    enabled: true,
    strategies:[
      { storage: sessionStorage, paths: ['sessionInfo'] },
    ]
  }
})

// 顶部菜单
export const menuTabStore = defineStore('menuTabInfo', { // 使用defineStore方法定义store
  state() { // state表示这个store里的状态，也就是存放数据的地方
    return {
      list: [], // 这里我们定义了一个数据叫userName，用于存放我们的用户名 
    }
  },
})